import { ElMessageBox, ElMessage } from 'element-plus';

const useMessage = () => ({
  onConfirm: (message, title, options) => new Promise((resolve, reject) => {
    ElMessageBox.confirm(message, title, {
      type: 'warning',
      ...options,
    }).then(() => {
      resolve();
    }).catch((err) => reject(err));
  }),
  message: (options) => {
    if (typeof options === 'object') {
      return ElMessage(options);
    }
    return ElMessage.success(options);
  },
});

export default useMessage;
